<style lang="scss" scoped>

@import "./_init.scss";
@import "./_form.scss";

</style>

<template lang="pug">
.VUE
    tab(login=1)
    form(@submit.prevent="submit" ref="form")
        .P
            input(name="account" v-model.trim="account" placeholder="请输入 邮箱 / 手机" spellcheck="false" required)
            label.I.I-user
        .P
            input(name="password" v-model.trim="password" type="password" placeholder="请输入 您的密码" required)
            label.I.I-password
        p
            button(type="submit") 登录

</template>

<script lang="coffee">
captcha = require './_captcha'
store = require 'store'

export default require('./_nologin.coffee') {
    data : ->
        {
            account:@$route.params.account or store.get('account') or ''
            password:""
        }

    components: {
        tab:require './_tab.vue'
    }

    mounted:->
        input = $(@$refs.form).find('input')
        if @account
            pos = 1
        else
            pos = 0

        $(input[pos]).focus().select()

    methods:{
        submit:->
            account = @account
            require('~coffee/_lib/session').login()
            captcha(
                @$refs.form
                "*auth/user/login"
                {
                    account
                    password:@password
                }
                =>
                    store.set 'account', account
                    GO.reload()
                (err)=>
                    if err.password
                        err.password = """密码错误 。 忘了 ？<a href="/auth/password/reset-#{$.escape account}">点此重置</a>"""
                    require('./_err/account') err, account
            )
    }
}
</script>

